package com.yonyou.brigade.third_parties.yihao.controller;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.basic_init.model.BriChannel;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.yihao.service.ICLYHOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/yihao")
public class BriController {

    @Autowired
    @Qualifier("briChannelServiceImpl")
    private IBriChannelService briChannelService;

    @RequestMapping(value = "/addTenantAndOrgpk",method = RequestMethod.POST)
    public @ResponseBody String addTenantAndOrgpk(@RequestBody JSONObject body){
        String tenant = body.getString("tenant");
        String orgpk = body.getString("orgpk");
        String phone = body.getString("phone");
        String config = body.getString("config");
        String channel = "clyh";
        Integer enable = 1;
        Integer is_pre_approve = 1;
        Integer open_type = 2;

        String[] sOrg = orgpk.split(",");
        BriChannel briChannel = new BriChannel();
        briChannel.setTenant(tenant);
        briChannel.setPhone(phone);
        briChannel.setConfig(config);
        briChannel.setEnable(enable);
        briChannel.setIsPreApprove(is_pre_approve);
        briChannel.setChannel(channel);
        briChannel.setOpenType(open_type);

        for (String org : sOrg){
            briChannel.setOrgpk(org);
            briChannelService.insert(briChannel);
        }

        return "success";
    }

}
